﻿@model ExcellentCRM.Site.Models.LocalPasswordModel

@using (Ajax.BeginForm("ChangePassword", "Account",
                       new AjaxOptions {HttpMethod = "post", OnSuccess = "changePassSucc"},
                       new {id = "changePassForm"}))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary()
    <div class="alert alert-error fade in hide">
        <button type="button" class="close" data-dismiss="alert">&times;</button>
        <div class="alert-content"></div>
    </div>
    <fieldset>
        <legend>修改密码</legend>
        <ol>
            <li>
                @Html.LabelFor(m => m.OldPassword)
                @Html.PasswordFor(m => m.OldPassword)
            </li>
            <li>
                @Html.LabelFor(m => m.NewPassword)
                @Html.PasswordFor(m => m.NewPassword)
            </li>
            <li>
                @Html.LabelFor(m => m.ConfirmPassword)
                @Html.PasswordFor(m => m.ConfirmPassword)
            </li>
        </ol>
        <input type="submit" value="保存" class="btn hidden" />
    </fieldset>
}
<script type="text/javascript">
    $(function() {
        $.validator.unobtrusive.parse('#changePassForm');
    });

    function changePassSucc(result) {
        if (!result || (!result.success && !result.message)) {
            alert('保存失败，未知原因');
            return;
        }
        var $alertContain = $('#changePassForm .alert'),
            $alertContent = $alertContain.find('.alert-content');
        if (!result.success && result.message) {
            $alertContent.html(result.message);
            $alertContain.removeClass('alert-success hide').addClass('alert-error').alert();
            return;
        }
        if (result.success) {
            $alertContent.html('保存完成,请重新登录');
            $alertContain.removeClass('alert-error hide').addClass('alert-success').alert();
            window.location.href = '@Url.Action("LogOff", "Account")';
        }
    }
</script>